home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / elispman.lha / elispman / elisp-19 (.txt) < prev    next >
GNU Info File  |  1993-06-01  |  50KB  |  906 lines

  1. This is Info file elisp, produced by Makeinfo-1.55 from the input file
  2. elisp.texi.
  3.    This is edition 2.0 of the GNU Emacs Lisp Reference Manual, for
  4. Emacs Version 19.
  5.    Published by the Free Software Foundation, 675 Massachusetts Avenue,
  6. Cambridge, MA 02139 USA
  7.    Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided that
  13. the entire resulting derived work is distributed under the terms of a
  14. permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that this permission notice may be stated in a
  18. translation approved by the Foundation.
  19. File: elisp,  Node: Auto-Saving,  Next: Reverting,  Prev: Backup Files,  Up: Backups and Auto-Saving
  20. Auto-Saving
  21. ===========
  22.    Emacs periodically saves all files that you are visiting; this is
  23. called "auto-saving".  Auto-saving prevents you from losing more than a
  24. limited amount of work if the system crashes.  By default, auto-saves
  25. happen every 300 keystrokes, or after around 30 seconds of idle time.
  26. *Note Auto-Save: (emacs)Auto-Save, for information on auto-save for
  27. users.  Here we describe the functions used to implement auto-saving
  28. and the variables that control them.
  29.  - Variable: buffer-auto-save-file-name
  30.      This buffer-local variable is the name of the file used for
  31.      auto-saving the current buffer.  It is `nil' if the buffer should
  32.      not be auto-saved.
  33.           buffer-auto-save-file-name
  34.           => "/xcssun/users/rms/lewis/#files.texi#"
  35.  - Command: auto-save-mode ARG
  36.      When used interactively without an argument, this command is a
  37.      toggle switch: it turns on auto-saving of the current buffer if it
  38.      is off, and vice-versa.  With an argument ARG, the command turns
  39.      auto-saving on if the value of ARG is `t', a nonempty list, or a
  40.      positive integer.  Otherwise, it turns auto-saving off.
  41.  - Function: auto-save-file-name-p FILENAME
  42.      This function returns a non-`nil' value if FILENAME is a string
  43.      that could be the name of an auto-save file.  It works based on
  44.      knowledge of the naming convention for auto-save files: a name that
  45.      begins and ends with hash marks (`#') is a possible auto-save file
  46.      name.  The argument FILENAME should not contain a directory part.
  47.           (make-auto-save-file-name)
  48.                => "/xcssun/users/rms/lewis/#files.texi#"
  49.           (auto-save-file-name-p "#files.texi#")
  50.                => 0
  51.           (auto-save-file-name-p "files.texi")
  52.                => nil
  53.      The standard definition of this function is as follows:
  54.           (defun auto-save-file-name-p (filename)
  55.             "Return non-nil if FILENAME can be yielded by..."
  56.             (string-match "^#.*#$" filename))
  57.      This function exists so that you can customize it if you wish to
  58.      change the naming convention for auto-save files.  If you redefine
  59.      it, be sure to redefine the function `make-auto-save-file-name'
  60.      correspondingly.
  61.  - Function: make-auto-save-file-name
  62.      This function returns the file name to use for auto-saving the
  63.      current buffer.  This is just the file name with hash marks (`#')
  64.      appended and prepended to it.  This function does not look at the
  65.      variable `auto-save-visited-file-name'; that should be checked
  66.      before this function is called.
  67.           (make-auto-save-file-name)
  68.                => "/xcssun/users/rms/lewis/#backup.texi#"
  69.      The standard definition of this function is as follows:
  70.           (defun make-auto-save-file-name ()
  71.             "Return file name to use for auto-saves \
  72.           of current buffer..."
  73.             (if buffer-file-name
  74.                 (concat
  75.                  (file-name-directory buffer-file-name)
  76.                  "#"
  77.                  (file-name-nondirectory buffer-file-name)
  78.                  "#")
  79.               (expand-file-name
  80.                (concat "#%" (buffer-name) "#"))))
  81.      This exists as a separate function so that you can redefine it to
  82.      customize the naming convention for auto-save files.  Be sure to
  83.      change `auto-save-file-name-p' in a corresponding way.
  84.  - Variable: auto-save-visited-file-name
  85.      If this variable is non-`nil', Emacs auto-saves buffers in the
  86.      files they are visiting.  That is, the auto-save is done in the
  87.      same file which you are editing.  Normally, this variable is
  88.      `nil', so auto-save files have distinct names that are created by
  89.      `make-auto-save-file-name'.
  90.      When you change the value of this variable, the value does not take
  91.      effect until the next time auto-save mode is reenabled in any given
  92.      buffer.  If auto-save mode is already enabled, auto-saves continue
  93.      to go in the same file name until `auto-save-mode' is called again.
  94.  - Function: recent-auto-save-p
  95.      This function returns `t' if the current buffer has been
  96.      auto-saved since the last time it was read in or saved.
  97.  - Function: set-buffer-auto-saved
  98.      This function marks the current buffer as auto-saved.  The buffer
  99.      will not be auto-saved again until the buffer text is changed
  100.      again.  The function returns `nil'.
  101.  - User Option: auto-save-interval
  102.      The value of this variable is the number of characters that Emacs
  103.      reads from the keyboard between auto-saves.  Each time this many
  104.      more characters are read, auto-saving is done for all buffers in
  105.      which it is enabled.
  106.  - User Option: auto-save-timeout
  107.      The value of this variable is the number of seconds of idle time
  108.      that should cause auto-saving.  Each time the user pauses for this
  109.      long, Emacs auto-saves any buffers that need it.  (Actually, the
  110.      specified timeout is multiplied by a factor depending on the size
  111.      of the current buffer.)
  112.  - Variable: auto-save-hook
  113.      This normal hook is run whenever an auto-save is about to happen.
  114.  - User Option: auto-save-default
  115.      If this variable is non-`nil', buffers that are visiting files
  116.      have auto-saving enabled by default.  Otherwise, they do not.
  117.  - Command: do-auto-save &optional NO-MESSAGE
  118.      This function auto-saves all buffers that need to be auto-saved.
  119.      This is all buffers for which auto-saving is enabled and that have
  120.      been changed since the last time they were auto-saved.
  121.      Normally, if any buffers are auto-saved, a message
  122.      `Auto-saving...' is displayed in the echo area while auto-saving is
  123.      going on.  However, if NO-MESSAGE is non-`nil', the message is
  124.      inhibited.
  125.  - Function: delete-auto-save-file-if-necessary
  126.      This function deletes the current buffer's auto-save file if
  127.      `delete-auto-save-files' is non-`nil'.  It is called every time a
  128.      buffer is saved.
  129.  - Variable: delete-auto-save-files
  130.      This variable is used by the function
  131.      `delete-auto-save-file-if-necessary'.  If it is non-`nil', Emacs
  132.      deletes auto-save files when a true save is done (in the visited
  133.      file).  This saves on disk space and unclutters your directory.
  134.  - Function: rename-auto-save-file
  135.      This function adjusts the current buffer's auto-save file name if
  136.      the visited file name has changed.  It also renames an existing
  137.      auto-save file.  If the visited file name has not changed, this
  138.      function does nothing.
  139. File: elisp,  Node: Reverting,  Prev: Auto-Saving,  Up: Backups and Auto-Saving
  140. Reverting
  141. =========
  142.    If you have made extensive changes to a file and then change your
  143. mind about them, you can get rid of them by reading in the previous
  144. version of the file with the `revert-buffer' command.  *Note Reverting
  145. a Buffer: (emacs)Reverting.
  146.  - Command: revert-buffer &optional CHECK-AUTO-SAVE NOCONFIRM
  147.      This command replaces the buffer text with the text of the visited
  148.      file on disk.  This action undoes all changes since the file was
  149.      visited or saved.
  150.      If the argument CHECK-AUTO-SAVE is non-`nil', and the latest
  151.      auto-save file is more recent than the visited file,
  152.      `revert-buffer' asks the user whether to use that instead.
  153.      Otherwise, it always uses the text of the visited file itself.
  154.      Interactively, CHECK-AUTO-SAVE is set if there is a numeric prefix
  155.      argument.
  156.      When the value of the NOCONFIRM argument is non-`nil',
  157.      `revert-buffer' does not ask for confirmation for the reversion
  158.      action.  This means that the buffer contents are deleted and
  159.      replaced by the text from the file on the disk, with no further
  160.      opportunities for the user to prevent it.
  161.      Since reverting works by deleting the entire text of the buffer and
  162.      inserting the file contents, all the buffer's markers are
  163.      relocated to point at the beginning of the buffer.  This is not
  164.      "correct", but then, there is no way to determine what would be
  165.      correct.  It is not possible to determine, from the text before
  166.      and after, which characters after reversion correspond to which
  167.      characters before.
  168.      If the value of the `revert-buffer-function' variable is
  169.      non-`nil', it is called as a function with no arguments to do the
  170.      work.
  171.  - Variable: revert-buffer-function
  172.      The value of this variable is the function to use to revert this
  173.      buffer; but if the value of this variable is `nil', then the
  174.      `revert-buffer' function carries out its default action.  Modes
  175.      such as Dired mode, in which the text being edited does not
  176.      consist of a file's contents but can be regenerated in some other
  177.      fashion, give this variable a buffer-local value that is a
  178.      function to regenerate the contents.
  179.  - Variable: revert-buffer-insert-file-contents-function
  180.      The value of this variable, if non-`nil', is the function to use
  181.      to insert contents when reverting this buffer.  The function
  182.      receives two arguments, first the file name to use, and second,
  183.      `t' if the user has asked to read the auto-save file.
  184.  - Command: recover-file FILENAME
  185.      This function visits FILENAME, but gets the contents from its last
  186.      auto-save file.  This is useful after the system has crashed, to
  187.      resume editing the same file without losing all the work done in
  188.      the previous session.
  189.      An error is signaled if there is no auto-save file for FILENAME,
  190.      or if FILENAME is newer than its auto-save file.  If FILENAME does
  191.      not exist, but its auto-save file does, then the auto-save file is
  192.      read as usual.  This last situation may occur if you visited a
  193.      nonexistent file and never actually saved it.
  194. File: elisp,  Node: Buffers,  Next: Windows,  Prev: Backups and Auto-Saving,  Up: Top
  195. Buffers
  196. *******
  197.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  198. are used to hold the contents of files that are being visited; there may
  199. also be buffers which are not visiting files.  While several buffers may
  200. exist at one time, exactly one buffer is designated the "current
  201. buffer" at any time.  Most editing commands act on the contents of the
  202. current buffer.  Each buffer, including the current buffer, may or may
  203. not be displayed in any windows.
  204. * Menu:
  205. * Buffer Basics::       What is a buffer?
  206. * Buffer Names::        Accessing and changing buffer names.
  207. * Buffer File Name::    The buffer file name indicates which file is visited.
  208. * Buffer Modification:: A buffer is "modified" if it needs to be saved.
  209. * Modification Time::   Determining whether the visited file was changed
  210.                          "behind Emacs's back".
  211. * Read Only Buffers::   Modifying text is not allowed in a read-only buffer.
  212. * The Buffer List::     How to look at all the existing buffers.
  213. * Creating Buffers::    Functions that create buffers.
  214. * Killing Buffers::     Buffers exist until explicitly killed.
  215. * Current Buffer::      Designating a buffer as current
  216.                           so primitives will access its contents.
  217. File: elisp,  Node: Buffer Basics,  Next: Buffer Names,  Prev: Buffers,  Up: Buffers
  218. Buffer Basics
  219. =============
  220.    A "buffer" is a Lisp object containing text to be edited.  Buffers
  221. are used to hold the contents of files that are being visited; there may
  222. also be buffers which are not visiting files.  While several buffers may
  223. exist at one time, exactly one buffer is designated the "current
  224. buffer" at any time.  Most editing commands act on the contents of the
  225. current buffer.  Each buffer, including the current buffer, may or may
  226. not be displayed in any windows.
  227.    Buffers in Emacs editing are objects which have distinct names and
  228. hold text that can be edited.  Buffers appear to Lisp programs as a
  229. special data type.  The contents of a buffer may be viewed as an
  230. extendable string; insertions and deletions may occur in any part of the
  231. buffer.  *Note Text::.
  232.    A Lisp buffer object contains numerous pieces of information.  Some
  233. of this information is directly accessible to the programmer through
  234. variables, while other information is only accessible through
  235. special-purpose functions.  For example, the width of a tab character is
  236. directly accessible through a variable, while the value of point is
  237. accessible only through a primitive function.
  238.    Buffer-specific information that is directly accessible is stored in
  239. "buffer-local" variable bindings, which are variable values that are
  240. effective only in a particular buffer.  This feature allows each buffer
  241. to override the values of certain variables.  Most major modes override
  242. variables such as `fill-column' or `comment-column' in this way.  For
  243. more information about buffer-local variables and functions related to
  244. them, see *Note Buffer-Local Variables::.
  245.    For functions and variables related to visiting files in buffers, see
  246. *Note Visiting Files:: and *Note Saving Buffers::.  For functions and
  247. variables related to the display of buffers in windows, see *Note
  248. Buffers and Windows::.
  249.  - Function: bufferp OBJECT
  250.      This function returns `t' if OBJECT is a buffer, `nil' otherwise.
  251. File: elisp,  Node: Buffer Names,  Next: Buffer File Name,  Prev: Buffer Basics,  Up: Buffers
  252. Buffer Names
  253. ============
  254.    Each buffer has a unique name, which is a string.  Many of the
  255. functions that work on buffers accept either a buffer or a buffer name
  256. as an argument.  Any argument called BUFFER-OR-NAME is of this sort,
  257. and an error is signaled if it is neither a string nor a buffer.  Any
  258. argument called BUFFER is required to be an actual buffer object, not a
  259. name.
  260.    Buffers that are ephemeral and generally uninteresting to the user
  261. have names starting with a space, which prevents them from being listed
  262. by the `list-buffers' or `buffer-menu' commands.  (A name starting with
  263. space also initially disables recording undo information; see *Note
  264. Undo::.)
  265.  - Function: buffer-name &optional BUFFER
  266.      This function returns the name of BUFFER as a string.  If BUFFER
  267.      is not supplied, it defaults to the current buffer.
  268.      If `buffer-name' returns `nil', it means that BUFFER has been
  269.      killed.  *Note Killing Buffers::.
  270.           (buffer-name)
  271.                => "buffers.texi"
  272.           
  273.           (setq foo (get-buffer "temp"))
  274.                => #<buffer temp>
  275.           (kill-buffer foo)
  276.                => nil
  277.           (buffer-name foo)
  278.                => nil
  279.           foo
  280.                => #<killed buffer>
  281.  - Command: rename-buffer NEWNAME &optional UNIQUE
  282.      This function renames the current buffer to NEWNAME.  An error is
  283.      signaled if NEWNAME is not a string, or if there is already a
  284.      buffer with that name.  The function returns `nil'.
  285.      Ordinarily, `rename-buffer' signals an error if NEWNAME is already
  286.      in use.  However, if UNIQUE is non-`nil', it modifies NEWNAME to
  287.      make a name that is not in use.  Interactively, you can make
  288.      UNIQUE non-`nil' with a numeric prefix argument.
  289.      One application of this command is to rename the `*shell*' buffer
  290.      to some other name, thus making it possible to create a second
  291.      shell buffer under the name `*shell*'.
  292.  - Function: get-buffer BUFFER-OR-NAME
  293.      This function returns the buffer specified by BUFFER-OR-NAME.  If
  294.      BUFFER-OR-NAME is a string and there is no buffer with that name,
  295.      the value is `nil'.  If BUFFER-OR-NAME is a buffer, it is returned
  296.      as given.  (That is not very useful, so the argument is usually a
  297.      name.)  For example:
  298.           (setq b (get-buffer "lewis"))
  299.                => #<buffer lewis>
  300.           (get-buffer b)
  301.                => #<buffer lewis>
  302.           (get-buffer "Frazzle-nots")
  303.                => nil
  304.      See also the function `get-buffer-create' in *Note Creating
  305.      Buffers::.
  306.  - Function: generate-new-buffer-name STARTING-NAME
  307.      This function returns a name that would be unique for a new
  308.      buffer--but does not create the buffer.  It starts with
  309.      STARTING-NAME, and produces a name not currently in use for any
  310.      buffer by appending a number inside of `<...>'.
  311.      See the related function `generate-new-buffer' in *Note Creating
  312.      Buffers::.
  313. File: elisp,  Node: Buffer File Name,  Next: Buffer Modification,  Prev: Buffer Names,  Up: Buffers
  314. Buffer File Name
  315. ================
  316.    The "buffer file name" is the name of the file that is visited in
  317. that buffer.  When a buffer is not visiting a file, its buffer file name
  318. is `nil'.  Most of the time, the buffer name is the same as the
  319. nondirectory part of the buffer file name, but the buffer file name and
  320. the buffer name are distinct and can be set independently.  *Note
  321. Visiting Files::.
  322.  - Function: buffer-file-name &optional BUFFER
  323.      This function returns the absolute file name of the file that
  324.      BUFFER is visiting.  If BUFFER is not visiting any file,
  325.      `buffer-file-name' returns `nil'.  If BUFFER is not supplied, it
  326.      defaults to the current buffer.
  327.           (buffer-file-name (other-buffer))
  328.                => "/usr/user/lewis/manual/files.texi"
  329.  - Variable: buffer-file-name
  330.      This buffer-local variable contains the name of the file being
  331.      visited in the current buffer, or `nil' if it is not visiting a
  332.      file.  It is a permanent local, unaffected by
  333.      `kill-local-variables'.
  334.           buffer-file-name
  335.                => "/usr/user/lewis/manual/buffers.texi"
  336.      It is risky to change this variable's value without doing various
  337.      other things.  See the definition of `set-visited-file-name' in
  338.      `files.el'; some of the things done there, such as changing the
  339.      buffer name, are not strictly necessary, but others are essential
  340.      to avoid confusing Emacs.
  341.  - Variable: buffer-file-truename
  342.      This buffer-local variable holds the truename of the file visited
  343.      in the current buffer, or `nil' if no file is visited.  It is a
  344.      permanent local, unaffected by `kill-local-variables'.  *Note
  345.      Truenames::.
  346.  - Variable: buffer-file-number
  347.      This buffer-local variable holds the file number and directory
  348.      device number of the file visited in the current buffer, or `nil'
  349.      if no file or a nonexistent file is visited.  It is a permanent
  350.      local, unaffected by `kill-local-variables'.  *Note Truenames::.
  351.      The value is normally a list of the form `(FILENUM DEVNUM)'.  This
  352.      pair of numbers uniquely identifies the file among all files
  353.      accessible on the system.  See the function `file-attributes', in
  354.      *Note File Attributes::, for more information about them.
  355.  - Function: get-file-buffer FILENAME
  356.      This function returns the buffer visiting file FILENAME.  If there
  357.      is no such buffer, it returns `nil'.  The argument FILENAME, which
  358.      must be a string, is expanded (*note File Name Expansion::.), then
  359.      compared against the visited file names of all live buffers.
  360.           (get-file-buffer "buffers.texi")
  361.               => #<buffer buffers.texi>
  362.      In unusual circumstances, there can be more than one buffer
  363.      visiting the same file name.  In such cases, this function returns
  364.      the first such buffer in the buffer list.
  365.  - Command: set-visited-file-name FILENAME
  366.      If FILENAME is a non-empty string, this function changes the name
  367.      of the file visited in current buffer to FILENAME.  (If the buffer
  368.      had no visited file, this gives it one.)  The *next time* the
  369.      buffer is saved it will go in the newly-specified file.  This
  370.      command marks the buffer as modified, since it does not (as far as
  371.      Emacs knows) match the contents of FILENAME, even if it matched the
  372.      former visited file.
  373.      If FILENAME is `nil' or the empty string, that stands for "no
  374.      visited file".  In this case, `set-visited-file-name' marks the
  375.      buffer as having no visited file.
  376.      When the function `set-visited-file-name' is called interactively,
  377.      it prompts for FILENAME in the minibuffer.
  378.      See also `clear-visited-file-modtime' and
  379.      `verify-visited-file-modtime' in *Note Buffer Modification::.
  380.  - Variable: list-buffers-directory
  381.      This buffer-local variable records a string to display in a buffer
  382.      listing in place of the visited file name, for buffers that don't
  383.      have a visited file name.  Dired buffers use this variable.
  384. File: elisp,  Node: Buffer Modification,  Next: Modification Time,  Prev: Buffer File Name,  Up: Buffers
  385. Buffer Modification
  386. ===================
  387.    Emacs keeps a flag called the "modified flag" for each buffer, to
  388. record whether you have changed the text of the buffer.  This flag is
  389. set to `t' whenever you alter the contents of the buffer, and cleared
  390. to `nil' when you save it.  Thus, the flag shows whether there are
  391. unsaved changes.  The flag value is normally shown in the mode line
  392. (*note Mode Line Variables::.), and controls saving (*note Saving
  393. Buffers::.) and auto-saving (*note Auto-Saving::.).
  394.    Some Lisp programs set the flag explicitly.  For example, the
  395. function `set-visited-file-name' sets the flag to `t', because the text
  396. does not match the newly-visited file, even if it is unchanged from the
  397. file formerly visited.
  398.    The functions that modify the contents of buffers are described in
  399. *Note Text::.
  400.  - Function: buffer-modified-p &optional BUFFER
  401.      This function returns `t' if the buffer BUFFER has been modified
  402.      since it was last read in from a file or saved, or `nil'
  403.      otherwise.  If BUFFER is not supplied, the current buffer is
  404.      tested.
  405.  - Function: set-buffer-modified-p FLAG
  406.      This function marks the current buffer as modified if FLAG is
  407.      non-`nil', or as unmodified if the flag is `nil'.
  408.      Another effect of calling this function is to cause unconditional
  409.      redisplay of the mode line for the current buffer.  In fact, the
  410.      function `force-mode-line-update' works by doing this:
  411.           (set-buffer-modified-p (buffer-modified-p))
  412.  - Command: not-modified
  413.      This command marks the current buffer as unmodified, and not
  414.      needing to be saved.  Don't use this function in programs, since
  415.      it prints a message in the echo area; use `set-buffer-modified-p'
  416.      (above) instead.
  417.  - Function: buffer-modified-tick &optional BUFFER
  418.      This function returns BUFFER`s modification-count.  This is a
  419.      counter that increments every time the buffer is modified.  If
  420.      BUFFER is `nil' (or omitted), the current buffer is used.
  421. File: elisp,  Node: Modification Time,  Next: Read Only Buffers,  Prev: Buffer Modification,  Up: Buffers
  422. Comparison of Modification Time
  423. ===============================
  424.    Suppose that you visit a file and make changes in its buffer, and
  425. meanwhile the file itself is changed on disk.  At this point, saving the
  426. buffer would overwrite the changes in the file.  Occasionally this may
  427. be what you want, but usually it would lose valuable information.  Emacs
  428. therefore checks the file's modification time using the functions
  429. described below before saving the file.
  430.  - Function: verify-visited-file-modtime BUFFER
  431.      This function compares Emacs's record of the modification time for
  432.      the file that the buffer is visiting against the actual
  433.      modification time of the file as recorded by the operating system.
  434.      The two should be the same unless some other process has written
  435.      the file since Emacs visited or saved it.
  436.      The function returns `t' if the last actual modification time and
  437.      Emacs's recorded modification time are the same, `nil' otherwise.
  438.  - Function: clear-visited-file-modtime
  439.      This function clears out the record of the last modification time
  440.      of the file being visited by the current buffer.  As a result, the
  441.      next attempt to save this buffer will not complain of a
  442.      discrepancy in file modification times.
  443.      This function is called in `set-visited-file-name' and other
  444.      exceptional places where the usual test to avoid overwriting a
  445.      changed file should not be done.
  446.  - Function: set-visited-file-modtime &optional TIME
  447.      This function updates the buffer's record of the last modification
  448.      time of the visited file, to the value specified by TIME if TIME
  449.      is not `nil', and otherwise to the last modification time of the
  450.      visited file.
  451.      If TIME is not `nil', it should have the form `(HIGH . LOW)' or
  452.      `(HIGH LOW)', in either case containing two integers, each of
  453.      which holds 16 bits of the time.  (This is the same format that
  454.      `file-attributes' uses to return time values; see *Note File
  455.      Attributes::.)
  456.      This function is useful if the buffer was not read from the file
  457.      normally, or if the file itself has been changed for some known
  458.      benign reason.
  459.  - Function: visited-file-modtime
  460.      This function returns the buffer's recorded last file modification
  461.      time, as a list of the form `(HIGH . LOW)'.  Note that this is not
  462.      identical to the last modification time of the file that is
  463.      visited (though under normal circumstances the values are equal).
  464.  - Function: ask-user-about-supersession-threat FN
  465.      This function is used to ask a user how to proceed after an
  466.      attempt to modify an obsolete buffer.  An "obsolete buffer" is an
  467.      unmodified buffer for which the associated file on disk is newer
  468.      than the last save-time of the buffer.  This means some other
  469.      program has probably altered the file.
  470.      This function is called automatically by Emacs on the proper
  471.      occasions.  It exists so you can customize Emacs by redefining it.
  472.      See the file `userlock.el' for the standard definition.
  473.      Depending on the user's answer, the function may return normally,
  474.      in which case the modification of the buffer proceeds, or it may
  475.      signal a `file-supersession' error with data `(FN)', in which case
  476.      the proposed buffer modification is not allowed.
  477.      See also the file locking mechanism in *Note File Locks::.
  478. File: elisp,  Node: Read Only Buffers,  Next: The Buffer List,  Prev: Modification Time,  Up: Buffers
  479. Read-Only Buffers
  480. =================
  481.    A buffer may be designated as "read-only".  This means that the
  482. buffer's contents may not be modified, although you may change your view
  483. of the contents by scrolling, narrowing, or widening, etc.
  484.    Read-only buffers are used in two kinds of situations:
  485.    * A buffer visiting a file is made read-only if the file is
  486.      write-protected.
  487.      Here, the purpose is to show the user that editing the buffer with
  488.      the aim of saving it in the file may be futile or undesirable.
  489.      The user who wants to change the buffer text despite this can do
  490.      so after clearing the read-only flag with the function
  491.      `toggle-read-only'.
  492.    * Modes such as Dired and Rmail make buffers read-only when altering
  493.      the contents with the usual editing commands is probably a mistake.
  494.      The special commands of the mode in question bind
  495.      `buffer-read-only' to `nil' (with `let') around the places where
  496.      they change the text.
  497.  - Variable: buffer-read-only
  498.      This buffer-local variable specifies whether the buffer is
  499.      read-only.  The buffer is read-only if this variable is non-`nil'.
  500.  - Command: toggle-read-only
  501.      This command changes whether the current buffer is read-only.  It
  502.      is intended for interactive use; don't use it in programs.  At any
  503.      given point in a program, you should know whether you want the
  504.      read-only flag on or off; so you can set `buffer-read-only'
  505.      explicitly to the proper value, `t' or `nil'.
  506.  - Function: barf-if-buffer-read-only
  507.      This function signals a `buffer-read-only' error if the current
  508.      buffer is read-only.  *Note Interactive Call::, for another way to
  509.      signal an error if the current buffer is read-only.
  510. File: elisp,  Node: The Buffer List,  Next: Creating Buffers,  Prev: Read Only Buffers,  Up: Buffers
  511. The Buffer List
  512. ===============
  513.    The "buffer list" is a list of all buffers that have not been
  514. killed.  The order of the buffers in the list is based primarily on how
  515. recently each buffer has been displayed in the selected window.  Several
  516. functions, notably `other-buffer', make use of this ordering.
  517.  - Function: buffer-list
  518.      This function returns a list of all buffers, including those whose
  519.      names begin with a space.  The elements are actual buffers, not
  520.      their names.
  521.           (buffer-list)
  522.                => (#<buffer buffers.texi>
  523.                    #<buffer  *Minibuf-1*> #<buffer buffer.c>
  524.                    #<buffer *Help*> #<buffer TAGS>)
  525.           
  526.           ;; Note that the name of the minibuffer
  527.           ;;   begins with a space!
  528.           
  529.           (mapcar (function buffer-name) (buffer-list))
  530.               => ("buffers.texi" " *Minibuf-1*"
  531.                    "buffer.c" "*Help*" "TAGS")
  532.      Buffers appear earlier in the list if they were current more
  533.      recently.
  534.      This list is a copy of a list used inside Emacs; modifying it has
  535.      no effect on the buffers.
  536.  - Function: other-buffer &optional BUFFER-OR-NAME VISIBLE-OK
  537.      This function returns the first buffer in the buffer list other
  538.      than BUFFER-OR-NAME.  Usually this is the buffer most recently
  539.      shown in the selected window, aside from BUFFER-OR-NAME.  Buffers
  540.      are moved to the front of the list when they are selected and to
  541.      the end when they are buried.  Buffers whose names start with a
  542.      space are not even considered.
  543.      If BUFFER-OR-NAME is not supplied (or if it is not a buffer), then
  544.      `other-buffer' returns the first buffer on the buffer list that is
  545.      not visible in any window.
  546.      Normally, `other-buffer' avoids returning a buffer visible in any
  547.      window, except as a last resort.  However, if VISIBLE-OK is
  548.      non-`nil', then a buffer displayed in some window is admissible to
  549.      return.
  550.      If no suitable buffer exists, the buffer `*scratch*' is returned
  551.      (and created, if necessary).
  552.  - Command: list-buffers &optional FILES-ONLY
  553.      This function displays a listing of the names of existing buffers.
  554.      It clears the buffer `*Buffer List*', then inserts the listing
  555.      into that buffer and displays it in a window.  `list-buffers' is
  556.      intended for interactive use, and is described fully in `The GNU
  557.      Emacs Manual'.  It returns `nil'.
  558.  - Command: bury-buffer &optional BUFFER-OR-NAME
  559.      This function puts BUFFER-OR-NAME at the end of the buffer list
  560.      without changing the order of any of the other buffers on the list.
  561.      This buffer therefore becomes the least desirable candidate for
  562.      `other-buffer' to return, and appears last in the list displayed by
  563.      `list-buffers'.
  564.      If BUFFER-OR-NAME is `nil' or omitted, this means to bury the
  565.      current buffer.  In addition, this switches to some other buffer
  566.      (obtained using `other-buffer') in the selected window.  If the
  567.      buffer is displayed in a window other than the selected one, it
  568.      remains there.
  569.      If you wish to remove a buffer from all the windows that display
  570.      it, you can do so with a loop that uses `get-buffer-window'.
  571.      *Note Buffers and Windows::.
  572. File: elisp,  Node: Creating Buffers,  Next: Killing Buffers,  Prev: The Buffer List,  Up: Buffers
  573. Creating Buffers
  574. ================
  575.    This section describes the two primitives for creating buffers.
  576. `get-buffer-create' creates a buffer if it finds no existing buffer;
  577. `generate-new-buffer' always creates a new buffer, and gives it a
  578. unique name.
  579.    Other functions you can use to create buffers include
  580. `with-output-to-temp-buffer' (*note Temporary Displays::.) and
  581. `create-file-buffer' (*note Visiting Files::.).
  582.  - Function: get-buffer-create NAME
  583.      This function returns a buffer named NAME.  If such a buffer
  584.      already exists, it is returned.  If such a buffer does not exist,
  585.      one is created and returned.  The buffer does not become the
  586.      current buffer--this function does not change which buffer is
  587.      current.
  588.      An error is signaled if NAME is not a string.
  589.           (get-buffer-create "foo")
  590.                => #<buffer foo>
  591.      The major mode for the new buffer is set by the value of
  592.      `default-major-mode'.  *Note Auto Major Mode::.
  593.  - Function: generate-new-buffer NAME
  594.      This function returns a newly created, empty buffer, but does not
  595.      make it current.  If there is no buffer named NAME, then that is
  596.      the name of the new buffer.  If that name is in use, this function
  597.      adds suffixes of the form `<N>' are added to NAME, where N is an
  598.      integer.  It tries successive integers starting with 2 until it
  599.      finds an available name.
  600.      An error is signaled if NAME is not a string.
  601.           (generate-new-buffer "bar")
  602.                => #<buffer bar>
  603.           (generate-new-buffer "bar")
  604.                => #<buffer bar<2>>
  605.           (generate-new-buffer "bar")
  606.                => #<buffer bar<3>>
  607.      The major mode for the new buffer is set by the value of
  608.      `default-major-mode'.  *Note Auto Major Mode::.
  609.      See the related function `generate-new-buffer-name' in *Note
  610.      Buffer Names::.
  611. File: elisp,  Node: Killing Buffers,  Next: Current Buffer,  Prev: Creating Buffers,  Up: Buffers
  612. Killing Buffers
  613. ===============
  614.    "Killing a buffer" makes its name unknown to Emacs and makes its
  615. space available for other use.
  616.    The buffer object for the buffer which has been killed remains in
  617. existence as long as anything refers to it, but it is specially marked
  618. so that you cannot make it current or display it.  Killed buffers retain
  619. their identity, however; two distinct buffers, when killed, remain
  620. distinct according to `eq'.
  621.    If you kill a buffer that is current or displayed in a window, Emacs
  622. automatically selects or displays some other buffer instead.  This means
  623. that killing a buffer can in general change the current buffer.
  624. Therefore, when you kill a buffer, you should also take the precautions
  625. associated with changing the current buffer (unless you happen to know
  626. that the buffer being killed isn't current).  *Note Current Buffer::.
  627.    The `buffer-name' of a killed buffer is `nil'.  You can use this
  628. feature to test whether a buffer has been killed:
  629.      (defun killed-buffer-p (buffer)
  630.        "Return t if BUFFER is killed."
  631.        (not (buffer-name buffer)))
  632.  - Command: kill-buffer BUFFER-OR-NAME
  633.      This function kills the buffer BUFFER-OR-NAME, freeing all its
  634.      memory for use as space for other buffers.  (Emacs version 18 and
  635.      older was unable to return the memory to the operating system.)
  636.      It returns `nil'.
  637.      Any processes that have this buffer as the `process-buffer' are
  638.      sent the `SIGHUP' signal, which normally causes them to terminate.
  639.      (The usual meaning of `SIGHUP' is that a dialup line has been
  640.      disconnected.)  *Note Deleting Processes::.
  641.      If the buffer is visiting a file when `kill-buffer' is called and
  642.      the buffer has not been saved since it was last modified, the user
  643.      is asked to confirm before the buffer is killed.  This is done
  644.      even if `kill-buffer' is not called interactively.  To prevent the
  645.      request for confirmation, clear the modified flag before calling
  646.      `kill-buffer'.  *Note Buffer Modification::.
  647.      Just before actually killing the buffer, after asking all
  648.      questions, `kill-buffer' runs the normal hook `kill-buffer-hook'.
  649.      The buffer to be killed is current when the hook functions run.
  650.      *Note Hooks::.
  651.      Killing a buffer that is already dead has no effect.
  652.           (kill-buffer "foo.unchanged")
  653.                => nil
  654.           (kill-buffer "foo.changed")
  655.           
  656.           ---------- Buffer: Minibuffer ----------
  657.           Buffer foo.changed modified; kill anyway? (yes or no) `yes'
  658.           ---------- Buffer: Minibuffer ----------
  659.           
  660.                => nil
  661. File: elisp,  Node: Current Buffer,  Prev: Killing Buffers,  Up: Buffers
  662. The Current Buffer
  663. ==================
  664.    There are, in general, many buffers in an Emacs session.  At any
  665. time, one of them is designated as the "current buffer".  This is the
  666. buffer in which most editing takes place, because most of the primitives
  667. for examining or changing text in a buffer operate implicitly on the
  668. current buffer (*note Text::.).  Normally the buffer that is displayed
  669. on the screen in the selected window is the current buffer, but this is
  670. not always so: a Lisp program can designate any buffer as current
  671. temporarily in order to operate on its contents, without changing what
  672. is displayed on the screen.
  673.    The way to designate a current buffer in a Lisp program is by calling
  674. `set-buffer'.  The specified buffer remains current until a new one is
  675. designated.
  676.    When an editing command returns to the editor command loop, the
  677. command loop designates the buffer displayed in the selected window as
  678. current, to prevent confusion: the buffer that the cursor is in, when
  679. Emacs reads a command, is the one to which the command will apply.
  680. (*Note Command Loop::.)  Therefore, `set-buffer' is not usable for
  681. switching visibly to a different buffer so that the user can edit it.
  682. For this, you must use the functions described in *Note Displaying
  683. Buffers::.
  684.    However, Lisp functions that change to a different current buffer
  685. should not leave it to the command loop to set it back afterwards.
  686. Editing commands written in Emacs Lisp can be called from other programs
  687. as well as from the command loop.  It is convenient for the caller if
  688. the subroutine does not change which buffer is current (unless, of
  689. course, that is the subroutine's purpose).  Therefore, you should
  690. normally use `set-buffer' within a `save-excursion' that will restore
  691. the current buffer when your program is done (*note Excursions::.).
  692. Here is an example, the code for the command `append-to-buffer' (with
  693. the documentation string abridged):
  694.      (defun append-to-buffer (buffer start end)
  695.        "Append to specified buffer the text of the region..."
  696.        (interactive "BAppend to buffer: \nr")
  697.        (let ((oldbuf (current-buffer)))
  698.          (save-excursion
  699.            (set-buffer (get-buffer-create buffer))
  700.            (insert-buffer-substring oldbuf start end))))
  701. This function binds a local variable to the current buffer, and then
  702. `save-excursion' records the values of point, the mark, and the
  703. original buffer.  Next, `set-buffer' makes another buffer current.
  704. Finally, `insert-buffer-substring' copies the string from the original
  705. current buffer to the new current buffer.
  706.    If the buffer appended to happens to be displayed in some window,
  707. then the next redisplay will show how its text has changed.  Otherwise,
  708. you will not see the change immediately on the screen.  The buffer
  709. becomes current temporarily during the execution of the command, but
  710. this does not cause it to be displayed.
  711.    Changing the current buffer between the binding and unbinding of a
  712. buffer-local variable can cause it to be bound in one buffer, and then
  713. unbound in another!  You can avoid this problem by using save-excursion
  714. to make sure that the buffer from which the variable was bound is
  715. current again whenever the variable is unbound.
  716.      (let (buffer-read-only)
  717.        (save-excursion
  718.          (set-buffer ...)
  719.          ...))
  720.  - Function: current-buffer
  721.      This function returns the current buffer.
  722.           (current-buffer)
  723.                => #<buffer buffers.texi>
  724.  - Function: set-buffer BUFFER-OR-NAME
  725.      This function makes BUFFER-OR-NAME the current buffer.  However,
  726.      it does not display the buffer in the currently selected window or
  727.      in any other window.  This means that the user cannot necessarily
  728.      see the buffer, but Lisp programs can in any case work on it.
  729.      This function returns the buffer identified by BUFFER-OR-NAME.  An
  730.      error is signaled if BUFFER-OR-NAME does not identify an existing
  731.      buffer.
  732. File: elisp,  Node: Windows,  Next: Frames,  Prev: Buffers,  Up: Top
  733. Windows
  734. *******
  735.    This chapter describes most of the functions and variables related to
  736. Emacs windows.  See *Note Emacs Display::, for information on how text
  737. is displayed in windows.
  738. * Menu:
  739. * Basic Windows::          Basic information on using windows.
  740. * Splitting Windows::      Splitting one window into two windows.
  741. * Deleting Windows::       Deleting a window gives its space to other windows.
  742. * Selecting Windows::      The selected window is the one that you edit in.
  743. * Cyclic Window Ordering:: Moving around the existing windows.
  744. * Buffers and Windows::    Each window displays the contents of a buffer.
  745. * Displaying Buffers::     Higher-lever functions for displaying a buffer
  746.                              and choosing a window for it.
  747. * Choosing Window::       How to choose a window for displaying a buffer.
  748. * Window Point::           Each window has its own location of point.
  749. * Window Start::           The display-start position controls which text
  750.                              is on-screen in the window.
  751. * Vertical Scrolling::     Moving text up and down in the window.
  752. * Horizontal Scrolling::   Moving text sideways on the window.
  753. * Size of Window::         Accessing the size of a window.
  754. * Resizing Windows::       Changing the size of a window.
  755. * Coordinates and Windows::Converting coordinates to windows.
  756. * Window Configurations::  Saving and restoring the state of the screen.
  757. File: elisp,  Node: Basic Windows,  Next: Splitting Windows,  Up: Windows
  758. Basic Concepts of Emacs Windows
  759. ===============================
  760.    A "window" is the physical area of the screen in which a buffer is
  761. displayed.  The term is also used to refer to a Lisp object which
  762. represents that screen area in Emacs Lisp.  It should be clear from the
  763. context which is meant.
  764.    There is always at least one window displayed on the screen, and
  765. there is exactly one window that we call the "selected window".  The
  766. cursor is in the selected window.  The selected window's buffer is
  767. usually the current buffer (except when `set-buffer' has been used.)
  768. *Note Current Buffer::.
  769.    For all intents, a window only exists while it is displayed on the
  770. terminal.  Once removed from the display, the window is effectively
  771. deleted and should not be used, *even though there may still be
  772. references to it* from other Lisp objects.  Restoring a saved window
  773. configuration is the only way for a window no longer on the screen to
  774. come back to life.  (*Note Deleting Windows::.)
  775.    Each window has the following attributes:
  776.    * containing frame
  777.    * window height
  778.    * window width
  779.    * window edges with respect to the screen or frame
  780.    * the buffer it displays
  781.    * position within the buffer at the upper left of the window
  782.    * the amount of horizontal scrolling, in columns
  783.    * point
  784.    * the mark
  785.    * how recently the window was selected
  786.    Applications use multiple windows for a variety of reasons, but most
  787. often to give different views of the same information.  In Rmail, for
  788. example, you can move through a summary buffer in one window while the
  789. other window shows messages one at a time as they are reached.
  790.    The term "window" in Emacs means something similar to what it means
  791. in the context of general puprpose window systems such as X, but not
  792. identical.  The X Window System subdivides the screen into X windows;
  793. Emacs uses one or more X windows, called "frames" in Emacs terminology,
  794. and subdivides each of them into (nonoverlapping) Emacs windows.  When
  795. you use Emacs on an ordinary display terminal, Emacs subdivides the
  796. terminal screen into Emacs windows.
  797.    Most window systems support arbitrarily located overlapping windows.
  798. In contrast, Emacs windows are "tiled"; they never overlap, and
  799. together they fill the whole of the screen or frame.  Because of the way
  800. in which Emacs creates new windows and resizes them, you can't create
  801. every conceivable tiling on an Emacs screen.  *Note Splitting Windows::.
  802. Also, see *Note Size of Window::.
  803.    *Note Emacs Display::, for information on how the contents of the
  804. window's buffer are displayed in the window.
  805.  - Function: windowp OBJECT
  806.      This function returns `t' if OBJECT is a window.
  807. File: elisp,  Node: Splitting Windows,  Next: Deleting Windows,  Prev: Basic Windows,  Up: Windows
  808. Splitting Windows
  809. =================
  810.    The functions described here are the primitives used to split a
  811. window into two windows.  Two higher level functions sometimes split a
  812. window, but not always: `pop-to-buffer' and `display-buffer' (*note
  813. Displaying Buffers::.).
  814.    The functions described here do not accept a buffer as an argument.
  815. They let the two "halves" of the split window display the same buffer
  816. previously visible in the window that was split.
  817.  - Function: one-window-p &optional NO-MINI
  818.      This function returns non-`nil' if there is only one window.  The
  819.      argument NO-MINI, if non-`nil', means don't count the minibuffer
  820.      even if it is active; otherwise, the minibuffer window is
  821.      included, if active, in the total number of windows which is
  822.      compared against one.
  823.  - Command: split-window &optional WINDOW SIZE HORIZONTAL
  824.      This function splits WINDOW into two windows.  The original window
  825.      WINDOW remains the selected window, but occupies only part of its
  826.      former screen area.  The rest is occupied by a newly created
  827.      window which is returned as the value of this function.
  828.      If HORIZONTAL is non-`nil', then WINDOW splits side by side,
  829.      keeping the leftmost SIZE columns and giving the rest of the
  830.      columns to the new window.  Otherwise, it splits into halves one
  831.      above the other, keeping the upper SIZE lines and giving the rest
  832.      of the lines to the new window.  The original window is therefore
  833.      the right-hand or upper of the two, and the new window is the
  834.      left-hand or lower.
  835.      If WINDOW is omitted or `nil', then the selected window is split.
  836.      If SIZE is omitted or `nil', then WINDOW is divided evenly into
  837.      two parts.  (If there is an odd line, it is allocated to the new
  838.      window.)  When `split-window' is called interactively, all its
  839.      arguments are `nil'.
  840.      The following example starts with one window on a screen that is 50
  841.      lines high by 80 columns wide; then the window is split.
  842.           (setq w (selected-window))
  843.                => #<window 8 on windows.texi>
  844.           (window-edges)          ; Edges in order:
  845.                => (0 0 80 50)     ;   left--top--right--bottom
  846.           
  847.           ;; Returns window created
  848.           (setq w2 (split-window w 15))
  849.                => #<window 28 on windows.texi>
  850.           (window-edges w2)
  851.                => (0 15 80 50)    ; Bottom window;
  852.                                   ;   top is line 15
  853.           (window-edges w)
  854.                => (0 0 80 15)     ; Top window
  855.      The screen looks like this:
  856.                    __________
  857.                   |          |  line 0
  858.                   |    w     |
  859.                   |__________|
  860.                   |          |  line 15
  861.                   |    w2    |
  862.                   |__________|
  863.                                 line 50
  864.            column 0   column 80
  865.      Next, the top window is split horizontally:
  866.           (setq w3 (split-window w 35 t))
  867.                => #<window 32 on windows.texi>
  868.           (window-edges w3)
  869.                => (35 0 80 15)  ; Left edge at column 35
  870.           (window-edges w)
  871.                => (0 0 35 15)   ; Right edge at column 35
  872.           (window-edges w2)
  873.                => (0 15 80 50)  ; Bottom window unchanged
  874.      Now, the screen looks like this:
  875.                column 35
  876.                    __________
  877.                   |   |      |  line 0
  878.                   | w |  w3  |
  879.                   |___|______|
  880.                   |          |  line 15
  881.                   |    w2    |
  882.                   |__________|
  883.                                 line 50
  884.            column 0   column 80
  885.  - Command: split-window-vertically SIZE
  886.      This function splits the selected window into two windows, one
  887.      above the other, leaving the selected window with SIZE lines.
  888.      This function is simply an interface to `split-windows'.  Here is
  889.      the complete function definition for it:
  890.           (defun split-window-vertically (&optional arg)
  891.             "Split selected window into two windows,
  892.           one above the other..."
  893.             (interactive "P")
  894.             (split-window nil (and arg (prefix-numeric-value arg))))
  895.  - Command: split-window-horizontally SIZE
  896.      This function splits the selected window into two windows
  897.      side-by-side, leaving the selected window with SIZE columns.
  898.      This function is simply an interface to `split-windows'.  Here is
  899.      the complete definition for `split-window-horizontally' (except for
  900.      part of the documentation string):
  901.           (defun split-window-horizontally (&optional arg)
  902.             "Split selected window into two windows
  903.           side by side..."
  904.             (interactive "P")
  905.             (split-window nil (and arg (prefix-numeric-value arg)) t))
  906.